<template>
  <div class="dialogPassword">
    <h1>输入Wi-Fi密码</h1>
    <div class="message"> <span>当前WIFi</span> <span>my-wifi</span></div>
    <el-form :rules="rules" ref="formDom" label-position="top" :model="formData" label-width="auto"
      style="max-width: 600px">

      <el-form-item label="Wi-Fi密码" prop="password">
        <el-input type="password" v-model="formData.password" />
      </el-form-item>
      <el-form-item label="Wi-Fi密码">
        <el-button>取消</el-button>
        <el-button :loading="btnLoading" @click="submit(formDom)" type="primary">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const formData = ref({
  password: ''
})
const emit = defineEmits(['openAlert'])
const btnLoading = ref(false)
const formDom = ref(null)
const rules = ref({
  password: [
    { required: true, message: '密码不能为空', trigger: 'blur' },
    {
      validator: (r, value, vb) => {
        btnLoading.value = true
        setTimeout(() => {
          btnLoading.value = false
          emit('openAlert')
          vb(new Error('密码错误'))
        }, 3000)
      }, trigger: 'submit'
    }
  ]
})

//提交
const submit = (dom) => {
  dom.validate((is) => {
    if (!is) return
    console.log(111)
  })
}
</script>

<style lang="scss" scoped>
.dialogPassword {
  width: 100%;
  padding: 0 40px;

  h1 {
    color: #191919;
    text-align: center;
    font-size: 15px;
  }

  .message {
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    margin-bottom: 24px;

    span {
      font-size: 14px;
      margin-bottom: 5px;

      &:nth-child(1) {
        color: #666;
      }

      &:nth-child(2) {
        font-weight: 600;
        color: #000000;
      }
    }
  }
}
</style>